
package com.xin.di.uav.applet.controller;

import com.xin.di.uav.applet.request.ServiceAreaAddParam;
import com.xin.di.uav.applet.request.ServiceAreaEditParam;
import com.xin.di.uav.applet.request.UserAccountsAddParam;
import com.xin.di.uav.applet.request.UserAccountsEditParam;
import com.xin.di.uav.applet.resp.UserAccountResp;
import com.xin.di.uav.applet.resp.UserResp;
import com.xin.di.uav.applet.service.NewUserService;
import com.xin.di.uav.applet.service.UserAccountService;
import com.xin.di.uav.common.request.common.IdRequest;
import com.xin.di.uav.common.utils.Rs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;


@RestController
@RequestMapping("/home/user-account/")
public class UserAccountController {

    @Autowired
    private UserAccountService userAccountService;

    @PostMapping("add")
    public Rs<Boolean> add(@RequestBody @Valid UserAccountsAddParam userAccountsAddParam) {
        return Rs.success(userAccountService.add(userAccountsAddParam));
    }

//    @DeleteMapping("{id}")
//    public Rs<Boolean> delete(@PathVariable String id) {
//        return Rs.success(serviceAreaService.delete(id));
//    }

    @PutMapping("update")
    public Rs<Boolean> update(@RequestBody @Valid UserAccountsEditParam userAccountsEditParam) {
        return Rs.success(userAccountService.update(userAccountsEditParam));
    }

    @PutMapping("update-status")
    public Rs<Boolean> updateStatus(@RequestBody @Valid IdRequest idRequest) {
        return Rs.success(userAccountService.updateStatus(idRequest));
    }

    @GetMapping("list")
    public Rs<UserAccountResp> list(@RequestParam int page, @RequestParam int pageSize
            , @RequestParam(required = false) String phone
            , @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime
            , @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        return Rs.success(userAccountService.list(page, pageSize, phone, startTime, endTime));
    }
}
